$(function(){
    // 登录
    $("#login").validate({
        rules: {
            currPass: {
                required: !0,
                pwd:true
            },
            newPass: {
                required: !0,
                pwd:true
            }
        },
        messages: {
            currPass: {
                required: e + "请输入您的原始密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            },
            newPass: {
                required: e + "请输入您的新密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            }
        },
        submitHandler: function (form) {
            var $form = $(form),
            data = $form.serialize();
            console.log(data)
            $.ajax({
                type : "post",xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                url : "./testdata.json",
                data : data,
                success : function(data) {
                    console.log(data)
                    /*if(data.success){
                        alert('密码修改成功！')
                        window.location.href='index.html'
                    }else {
                        alert(data.msg)
                    }*/
                },
                error : function(){
                    alert("登录失败");
                }
            });
        }
    });
   // 邮箱验证
    var validate_times=0;
    $("#mail_validate form").validate({
        rules: {
            currPass: {
                required: !0,
                pwd:true
            },
            newPass: {
                required: !0,
                pwd:true
            }
        },
        messages: {
            currPass: {
                required: e + "请输入您的原始密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            },
            newPass: {
                required: e + "请输入您的新密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            }
        },
        submitHandler: function (form) {
            // validate_times++;
            // console.log(validate_times)
            /*if(validate_times>3&&){
                validate_times=0;
                return;
            }*/
            var $form = $(form);
            data = $form.serialize();
            console.log(data)
            $("#mail_validate button").attr("disabled", true);
            $.ajax({
                type : "post",xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                url : "./testdata.json",
                data : data,
                success : function(data) {
                    console.log(data)
                    $("#mail_validate h2").text('发送成功！');
                    $("#mail_validate p").text('请登录邮箱点击邮箱内的链接进行验证');
                    settime($("#mail_validate"),["邮箱验证",
                        "输入你预留的邮箱地址，我们会发送一封邮件到你的邮箱，请查收进行验证"]);
                    //
                    // $("#mail_validate button").text('重新发送'+time);
                    /*if(data.success){
                        alert('密码修改成功！')
                        window.location.href='index.html'
                    }else {
                        alert(data.msg)
                    }*/
                },
                error : function(){
                    alert("登录失败");
                }
            });
        }
    });

    // 激活码验证
    $("#active_code form").validate({
        rules: {
            currPass: {
                required: !0,
                pwd:true
            },
            newPass: {
                required: !0,
                pwd:true
            }
        },
        messages: {
            currPass: {
                required: e + "请输入您的原始密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            },
            newPass: {
                required: e + "请输入您的新密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            }
        },
        submitHandler: function (form) {
            var $form = $(form);
            data1 = $form.find('input').val();
            console.log(data1);
            $.ajax({
                type : "get",xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                url : url_web+"sys/user/enableUser/"+data1,
                success : function(data) {
                    console.log(data);
                    window.location.href="pwd_setting.html?phone="+data.data.phone+"&code="+data1; /*+data.data.phone*/
                },
                error : function(){
                    alert("请求失败!");
                }
            });
        }
    });
    // 完善个人信息
    var Request=GetRequest();
    console.log(Request)
    $(".person_info_add form").validate({
        rules: {
            currPass: {
                required: !0,
                pwd:true
            },
            newPass: {
                required: !0,
                pwd:true
            }
        },
        messages: {
            currPass: {
                required: e + "请输入您的原始密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            },
            newPass: {
                required: e + "请输入您的新密码",
                pwd: e + "密码必须由8以上的数字和字母组成"
            }
        },
        submitHandler: function (form) {
            var $form = $(form);
            data = $form.serialize();
            data+=('&id='+Request.id)
            console.log(data);
            $.ajax({
                type : "put",xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,data:data,
                url : url_web+"sys/user",
                success : function(data) {
                    console.log(data);
                    window.location.href='index.html'; /*+data.data.phone*/
                },
                error : function(){
                    alert("请求失败!");
                }
            });
        }
    });

})
